import { fetchWaybillDetailAPI, fetchWaybillListAPI } from '@/api/business/waybillAPI'

const actions = {
  /*
  * 获取运单分页的action
  *  */
  async fetchWaybillListAction(context, pageParams) {
    const { data } = await fetchWaybillListAPI(pageParams)
    context.commit('setWaybillListMutation', data)
  },

  /*
  *
  * 获取运单详情的action
  *  */
  async fetchWaybillDetailAction(context, id) {
    const { data } = await fetchWaybillDetailAPI(id)
    context.commit('setWaybillDetailMutation', data)
  }
}
const mutations = {
  /*
  * 设置运单分页的mutation
  *  */
  setWaybillListMutation(state, { counts, items }) {
    state.waybillList = items
    state.counts = Number(counts)
  },
  /*
  * 设置运单详情的mutation
  *  */
  setWaybillDetailMutation(state, waybillDetail) {
    state.waybillDetailShow = waybillDetail
  }
}
const state = () => {
  return {
    counts: 0,
    waybillList: [],
    waybillDetailShow: {}
  }
}

export default {
  actions,
  mutations,
  state,
  namespaced: true
}
